package com.yt.website.action;

import com.yt.core.dao.PagingBean;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.website.api.interfaces.IndexSaleService;
import com.yt.website.api.model.IndexSale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/index")
public class IndexAction {

	private final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private IndexSaleService indexSaleService;


	@RequestMapping("/list")
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView("index");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	/**
	 * 健康管理
	 *
	 * @return
	 */
	@RequestMapping("/healthControl")
	public ModelAndView healthControl() {
		ModelAndView mav = new ModelAndView("/health/healthControl");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	@RequestMapping("/healthTest")
	public ModelAndView healthTest() {
		ModelAndView mav = new ModelAndView("/health/physical");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	@RequestMapping("/customService")
	public ModelAndView customService() {
		ModelAndView mav = new ModelAndView("/health/healthControl");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}


	@RequestMapping("/healthTong")
	public ModelAndView healthTong() {
		ModelAndView mav = new ModelAndView("/health/through");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	@RequestMapping("/femaleHealth")
	public ModelAndView femaleHealth() {
		ModelAndView mav = new ModelAndView("/health/healthControl");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	@RequestMapping("/healthMail")
	public ModelAndView healthMail() {
		ModelAndView mav = new ModelAndView("/health/healthControl");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}

	@RequestMapping("/diseaseQuery")
	public ModelAndView diseaseQuery() {
		ModelAndView mav = new ModelAndView("/health/disease");
		try {
			//首页轮播图广告
			QueryFilter filter = new DynamicSQLFilterImpl();
			filter.setPagingBean(new PagingBean(0, 5));
			filter.setSortField("sortBy", true);
			List<IndexSale> indexSaleList = indexSaleService.find(filter);
			mav.addObject("indexList", indexSaleList);

		} catch (Exception e) {
			logger.error("添加或修改出错：{}", e.getMessage(), e);
		}
		return mav;
	}
}
